//
//  GYKeyTableViewCell.m
//  LockManagement
//
//  Created by apple on 2018/7/25.
//  Copyright © 2018年 yunjiazhineng. All rights reserved.
//

static NSString *keyCellIdentifier = @"keyCellIdentifier";


#import "GYKeyTableViewCell.h"
#import "GYUserInfo.h"


@interface GYKeyTableViewCell()

@property (weak, nonatomic) IBOutlet UIImageView *keyImageView;
@property (weak, nonatomic) IBOutlet UILabel *keyNameLable;
@property (weak, nonatomic) IBOutlet UILabel *userNameLbale;
@property (weak, nonatomic) IBOutlet UILabel *userPhoneLable;
@property (weak, nonatomic) IBOutlet UIImageView *keyElecImageView;
@property (weak, nonatomic) IBOutlet UIImageView *keyStateImageView;
@property (weak, nonatomic) IBOutlet UILabel *markLable;


@end

@implementation GYKeyTableViewCell

+ (instancetype)cellWithTableView:(UITableView *)tableView {
    GYKeyTableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:keyCellIdentifier];
    if (cell == nil) {
        cell = [[[NSBundle mainBundle] loadNibNamed:NSStringFromClass(self) owner:nil options:nil] firstObject];
    }
    
    return cell;
}

- (CGFloat)cellHeight {
    return CGRectGetMaxY(self.markLable.frame);
}

- (void)setKeyModel:(GYKey *)keyModel {
    _keyModel = keyModel;
    
    self.keyNameLable.text = keyModel.keyName;
    self.userPhoneLable.text = keyModel.keyMac;

    //设置名字
    self.userNameLbale.text = [[GYUserInfo loadUserInfo] userName];
}

- (void)setConnectKeyMac:(NSString *)connectKeyMac {
    _connectKeyMac = connectKeyMac;
    
    //1.获取蓝牙的钥匙的MAC地址
    NSString *keyMac = @"";
    NSArray *strs = [self.keyModel.keyMac componentsSeparatedByString:@"-"];
    for (NSString *str in strs) {
        keyMac = [keyMac stringByAppendingString:str];
    }
    
    if ([connectKeyMac isEqualToString:keyMac]) {
        self.keyStateImageView.image = [UIImage imageNamed:@"kaiguan"];
    }else {
        self.keyStateImageView.image = [UIImage imageNamed:@"wu"];
    }
}












@end
